package com.un.core.utils;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.un.core.entity.BaseEntity;

import java.util.ArrayList;
import java.util.Collections;

/**
 * @Author xingjian
 * @Date 2023-01-12
 **/
public class Code {
    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:mysql://123.60.98.215:8306/stereotyped-writing?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=false", "root", "A@jian51sql")
                .globalConfig(builder -> {
                    builder.author("xingjian") // 设置作者
                            .dateType(DateType.ONLY_DATE)
                            .fileOverride() // 覆盖已生成文件
                            .outputDir("/Users/xiaowu/Data"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.un") // 设置父包名
                            .moduleName("sys") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.xml, "/Users/xiaowu/Data/mapper")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    ArrayList<String> strings = new ArrayList<>();
                    strings.add("create_time");
                    strings.add("update_time");
                    strings.add("data_status");
                    strings.add("id");
                    builder.addInclude("sys_user")
                            .entityBuilder()
                            .superClass(BaseEntity.class)
                            .addSuperEntityColumns(strings);
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }

}
